package com.jianwei.service.segment;

import com.jianwei.configuration.Module;
import com.jianwei.service.generator.AbstractIdGeneratorFactory;
import com.jianwei.service.generator.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;

@Module("segment.enable")
@Component
public class SegmentIdGeneratorFactory extends AbstractIdGeneratorFactory {
    @Autowired
    private SegmentService segmentService;

    @Autowired
    @Qualifier(value = "fetchNextSegmentExecutor")
    private ExecutorService fetchNextSegmentExecutor;

    @Override
    protected IdGenerator createIdGenerator(String businessType) {
        return new SegmentCachedIdGenerator(fetchNextSegmentExecutor, segmentService, businessType);
    }
}
